C:\> java TokenTester Enter a string: 12 8 5 32 12 8 5 32
Here is the program again, but this time with the delimiters specified in the constructor. The delimiters are now space, equals, plus, and minus.
import java.io.*;
import java.util.*;
public class TokenTester
{
public static void main ( String[] args ) throws IOException
{
BufferedReader stdin =
new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter a string:");
String data = stdin.readLine();
StringTokenizer tok =
new StringTokenizer( data, " =+-" ); // note the space before =
while ( tok.hasMoreTokens() )
System.out.println( tok.nextToken() );
}
}